﻿using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        public string FriedLink()
        {
            string mystyle = this.Label_Inserted;
            string str_ShowMode = this.GetParamValue("YX:ShowMode");//显示模式
            string str_NameCharacter = this.GetParamValue("YX:NameCharacter");
            string str_CompositorType = this.GetParamValue("YX:CompositorType");//是否排序
            string str_ShowRows = this.GetParamValue("YX:ShowRows");
            string str_ShowColumns = this.GetParamValue("YX:ShowColumns");
            string str_FriedLinkShowType = this.GetParamValue("YX:FriedLinkShowType");
            int NameCharacter = 4;
            if (ChangeHope.Common.ValidateHelper.IsNumber(str_NameCharacter))
            {
                NameCharacter = Convert.ToInt32(str_NameCharacter);
            }
            int ShowRows = 1;//显示行
            if (ChangeHope.Common.ValidateHelper.IsNumber(str_ShowRows))
            {
                ShowRows = Convert.ToInt32(str_ShowRows);
            }
            int ShowColumns = 1;//显示列
            if (ChangeHope.Common.ValidateHelper.IsNumber(str_ShowColumns))
            {
                ShowColumns = Convert.ToInt32(str_ShowColumns);
            }
            string str_TempletLayout = this.GetParamValue("YX:TempletLayout");//布局方式
            bool WhetherOmit = Convert.ToBoolean(this.GetParamValue("YX:WhetherOmit"));//是否省略
            string Comd = "";//条件


            #region 查询参数
            if (!string.IsNullOrEmpty(str_ShowMode))//显示模式
            {
                switch (str_ShowMode)
                {
                    case "2":
                        Comd += "";
                        break;
                    case "1":

                        Comd += " and sitestate=1";
                        break;
                    default:
                        break;
                }
            }
            if (!string.IsNullOrEmpty(str_FriedLinkShowType))
            {
                if (str_FriedLinkShowType == "1")
                {
                    Comd += " and putouttyid=0";
                }
                else if (str_FriedLinkShowType == "2")
                {
                    int userId = ChangeHope.WebPage.PageRequest.GetQueryInt("UserId");
                    Comd += " and putouttyid=1 and putoutid=" + userId.ToString() + "";
                }
            }
            string OrderFields = string.Empty;
            if (!string.IsNullOrEmpty(str_CompositorType))//排序方式
            {
                if (str_CompositorType.Equals("desc"))
                {
                    OrderFields += " [order by] ID desc";
                }
                else
                {
                    OrderFields += " [order by] ID asc";
                }
            }
            #endregion
            StringBuilder Shtml = new StringBuilder();
            YXShop.BLL.Accessories.Hailhellowlink hlbll = new YXShop.BLL.Accessories.Hailhellowlink();
            ChangeHope.DataBase.DataByPage dataPage = hlbll.GetList(OrderFields, ShowRows * ShowColumns, Comd);
            string strcontent = "";
            int j = 1;
            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    strcontent = mystyle;
                    if (mystyle.IndexOf("[#SiteName]") > -1)
                    {
                        if (WhetherOmit)
                        {
                            strcontent = strcontent.Replace("[#SiteName]", ChangeHope.Common.StringHelper.SubStringAndAppend(dataPage.DataReader["sitename"].ToString(), NameCharacter, "..."));
                        }
                        else
                        {
                            strcontent = strcontent.Replace("[#SiteName]", ChangeHope.Common.StringHelper.SubString(dataPage.DataReader["sitename"].ToString(), NameCharacter));
                        }
                    }
                    if (strcontent.Contains("{#SiteUrl}"))
                    {
                        strcontent = strcontent.Replace("{#SiteUrl}", dataPage.DataReader["siteurl"].ToString());
                    }
                    if (strcontent.Contains("{#SiteLogo}"))
                    {
                        string logoUrl = sp.DummyPaht + dataPage.DataReader["sitelogo"].ToString();
                        string logo = dataPage.DataReader["sitelogo"].ToString();
                        if (!string.IsNullOrEmpty(logo.Trim()))
                        {
                            if (logo.Contains("http://") || logo.Contains("HTTP://"))
                            {
                                logoUrl = dataPage.DataReader["sitelogo"].ToString();
                            }
                        }
                        strcontent = strcontent.Replace("[#SiteLogo]", logoUrl);
                    }
                    Shtml.Append(strcontent);
                    j++;
                    if (j % ShowColumns == 0)
                    {
                        if (!str_TempletLayout.Equals("0"))
                        {
                            Shtml.Append("</tr><tr>");
                        }
                    }
                }
            }
            else
            {
                return "暂无信息。";
            }
            return Shtml.ToString();
        }
    }
}
